<template>
	<view>
		<view class="top_title">
			<text>我的收藏({{total}})</text>
		</view>
		<view class="content">
			<view v-for="(item,index) in activityList" :key="index">
				<buji-goods :goods="item" @click="Todetails(item)" show-time="true"></buji-goods>
			</view>
		</view>
		<view class="bottom">
			<text>没有更多啦~~~</text>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'

	export default {
		data() {
			return {
				activityList: [],
			};
		},
		computed: {
			...mapState('buji_search', ['refresh']),
			
			total() {
				return this.activityList.length
			}
		},
		methods: {
			...mapMutations('buji_search', ['updateGoods', 'updateClass']),

			Todetails(item) {
				this.updateGoods(item);
				uni.navigateTo({
					url: "/subpkg/details/details"
				})
			},
			getCollections() {
				this.activityList = [],
				wx.cloud.callFunction({
					name: 'getCollections',
					// complete: res => {
					// 	 console.info('complete', res);
					// },
					success: res => {
						console.info('success', res.result);
						for (let i = 0; i < res.result.data.length; i++) {
							this.activityList.push(res.result.data[i]);
						}
						for (let j = 0; j < this.activityList.length; j++) {
							let date = this.activityList[j].time
							let startTime = new Date(date).getTime();
							let nowTime = Date.parse(new Date());
							let time = parseInt((nowTime - startTime) / 1000);
							if (time < 60) {
								this.activityList[j].time = `${time}秒`
							} else if (time < 3600) {
								let temp = parseInt(time / 60)
								this.activityList[j].time = `${temp}分钟`
							} else if (time < 86400) {
								let temp = parseInt(time / 3600)
								this.activityList[j].time = `${temp}小时`
							} else if (time < 2592000) {
								let temp = parseInt(time / 86400)
								this.activityList[j].time = `${temp}天`
							} else if (time < 31104000) {
								let temp = parseInt(time / 2592000)
								this.activityList[j].time = `${temp}月`
							} else {
								let temp = parseInt(time / 31104000)
								this.activityList[j].time = `${temp}年`
							}
						}
					},
					fail: res => {
						console.info('fail', res);
					}
				});
			},
		},
		onShow() {
			this.getCollections()
			
		},
	}
</script>

<style lang="scss">
	.top_title {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 75rpx;
		line-height: 75rpx;
		background-color: #efefef;
		text-align: center;
		border-bottom: solid 1px #8c8c8c;
	}

	.content {
		margin-top: 100rpx;
	}

	.bottom {
		height: 200rpx;
		line-height: 200rpx;
		text-align: center;
		font-size: 36rpx;
	}
</style>
